package com.auth.web;

import com.alibaba.fastjson.JSON;
import com.auth.token.base.TokenGroup;
import com.auth.token.device.DeviceInfo;
import com.auth.token.device.DeviceTokenClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author: 王霄
 * @date: 2022/1/20 21:32
 */
@RestController
@RequestMapping("/device")
@Slf4j
public class DeviceController {

    @Resource
    private DeviceTokenClient deviceTokenClient;

    @GetMapping("/login")
    public TokenGroup login() {
        DeviceInfo deviceInfo = new DeviceInfo("000000000000", "ABCD");
        TokenGroup tokenGroup = deviceTokenClient.askToken(deviceInfo);
        log.info(JSON.toJSONString(tokenGroup));
        return tokenGroup;
    }


    @GetMapping("/refreshToken")
    public TokenGroup refreshToken(String refreshToken) {
        TokenGroup tokenGroup = deviceTokenClient.refreshToken(refreshToken);
        log.info(JSON.toJSONString(tokenGroup));
        return tokenGroup;
    }
}